package com.toune.blackmusic.util;

import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.toune.blackmusic.R;
import com.vondear.rxui.view.dialog.RxDialog;
import com.vondear.rxui.view.progressing.style.ChasingDots;

/**
 * Created by Administrator on 2018/5/5.
 */

public class MyLodingDialog extends RxDialog {
    private View view;
    private static String msgStr;

    private static MyLodingDialog myLodingDialog;

    public static MyLodingDialog newInstance(Context context,String str) {
        if (myLodingDialog == null) {
            myLodingDialog = new MyLodingDialog(context);
        }
        msgStr = str;
        return myLodingDialog;
    }

    public static void hideMySelf() {
        if (myLodingDialog != null) {
            myLodingDialog.dismiss();
            msgStr = null;
        }
    }

    public MyLodingDialog(Context context, int themeResId) {
        super(context, themeResId);
    }

    public MyLodingDialog(Context context, boolean cancelable, DialogInterface.OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    public MyLodingDialog(Context context) {
        super(context);
    }

    public MyLodingDialog(Context context, float alpha, int gravity) {
        super(context, alpha, gravity);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        view = View.inflate(getContext(), R.layout.layout_loading, null);
        setContentView(view);
        int color = android.graphics.Color.parseColor("#89CFF0");
        ProgressBar progressBar = (ProgressBar) view.findViewById(R.id.progress);
         //正方形碎片
//        CubeGrid cubeGrid = new CubeGrid();
//        cubeGrid.setColor(color);
//        progressBar.setIndeterminateDrawable(cubeGrid);
        //圆圈扩大缩小
//        DoubleBounce doubleBounce = new DoubleBounce();
//        doubleBounce.setBounds(0, 0, 100, 100);
//        doubleBounce.setColor(android.graphics.Color.parseColor("#89CFF0"));
//        progressBar.setIndeterminateDrawable(doubleBounce);
        ChasingDots chasingDots = new ChasingDots();
        chasingDots.setColor(color);
        progressBar.setIndeterminateDrawable(chasingDots);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        params.gravity = Gravity.CENTER;

        TextView textView = view.findViewById(R.id.msg_tv);
        if (msgStr != null) {
            textView.setText(msgStr);
        }
    }

}
